$(document).ready(function(){

	$(".f_sort").live("click", function(){
		sort(this);
	}); 
}); 

function sort(obj){
	var Method	=	$(obj).attr("method");
	if(Method=="1"){
		$(obj).attr("method","0");
	}else{
		$(obj).attr("method","1");
	}
	var index = $(obj).index("th");
		
	var Divs	=	$(obj).parents("table").find("tbody").find("tr").toArray();
	var length	=	Divs.length;
	var DivArray	= new Array();

	for(var i=0;i<length;i++)
	{
		DivArray[i]	= Divs[i];
	}
		
	var $tr = Divs[1];
	
	DivArray.sort(GetSort("sortVal",Method,index));
	try
	{
		var SortDiv	=	document.createDocumentFragment();
		for(var i=0;i<length;i++)
		{
			SortDiv.appendChild(DivArray[i]);
		}
		$(obj).parents("table").find("tbody").html(SortDiv);
	}
	catch(Err)
	{
		alert(Err.description);
	}
}
function GetSort(attributeName,Method,index)
{
	return function KGetSort(tr1,tr2)
	{
		var x1 =  tr1.cells[index].getAttribute(attributeName).replace(":",".");
		var y1 =  tr2.cells[index].getAttribute(attributeName).replace(":",".");
		var x	=	parseFloat(x1);
		var y	=	parseFloat(y1);
		if(Method==1)
		{
			if(x<y)
			{
				return -1;
			}
			else
			{
				return 1;
			}
		}else{
			if(x>y)
			{
				return -1;
			}
			else
			{
				return 1;
			}		
		}
	}
}
